package com.woniuxy.kaer.shop.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.form.PageForm;
import com.woniuxy.kaer.form.RefundForm;
import com.woniuxy.kaer.param.RefundParam;
import com.woniuxy.kaer.shop.service.RefundRequestsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 *  退款申请
 * </p>
 *
 * @author 郭建东
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/refundRequests")
@Api(tags = "退款管理")
public class RefundRequestsController {

    @Resource
    private RefundRequestsService refundRequestsService;

    @Resource
    private JwtUtil jwtUtil;

    //退款申请
    @PostMapping("/refundApply")
    @ApiOperation("退款申请")
    public Result refundApply(@RequestBody RefundForm from, @RequestHeader("token") String token)throws Exception{
        Integer userId = jwtUtil.parseToken(token).get("userId", Integer.class);
        refundRequestsService.applyRefund(BeanUtil.toBean(from, RefundParam.class),userId);
        return Result.succeed("退款申请成功",null);
    }

    //处理退款申请
    @PostMapping("/hanldeApply")
    @ApiOperation("处理退款申请")
    public Result handleRefundApply(String refundId,Integer state)throws Exception{
        refundRequestsService.handleRefundApply(refundId,state);
        return Result.succeed("处理成功",null);
    }

    @PostMapping("/searchRefund")
    @ApiOperation("查询退款申请")
    public Result searchRefund(@RequestBody PageForm form)throws Exception{

        return Result.succeed("查询成功",refundRequestsService.searchRefund(form));
    }
}

